package com.gxa.modules.app.outpatient.onlinepay.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxa.common.utils.UUIDUtils;
import com.gxa.modules.app.outpatient.onlinepay.mapper.RechargeOrderInfoAppMapper;
import com.gxa.modules.app.outpatient.onlinepay.service.OutpatientRechargeRecordsAppService;
import com.gxa.modules.app.outpatient.onlinepay.service.RechargeOrderInfoAppService;
import com.gxa.modules.model.entity.fee.RechargeOrderInfo;
import com.gxa.modules.pc.fee.mapper.RechargeOrderInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.UUID;

/**
 * <p>
 * 门诊充值信息表  服务实现类
 * </p>
 *
 * @author gxa
 * @since 2022-11-12 05:31:54
 */
@Service
public class RechargeOrderInfoAppServiceImpl implements RechargeOrderInfoAppService {

    @Autowired
    private RechargeOrderInfoAppMapper rechargeOrderInfoAppMapper;

    @Autowired
    private OutpatientRechargeRecordsAppService orrs;

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public void addOrderDetail(double rechargeMoney,double cardBalance,Integer id) {

        String orderId = "ZY" + UUIDUtils.createOnlyId();
        //创建一个RechargeOrderInfo
        double totalmm = rechargeMoney + cardBalance;
        RechargeOrderInfo rechargeOrderInfo = new RechargeOrderInfo();
        rechargeOrderInfo.setOrderId(orderId)
                .setExpenseType(1)
                .setCardBalance(totalmm)
                .setBusinessType(0)
                .setOrderStatus(1)
                .setOrderSource(0)
                .setTotalRecharge(rechargeMoney);
        rechargeOrderInfoAppMapper.insert(rechargeOrderInfo);
        orrs.addRechargeRecords(orderId,id);
    }
}
